<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="__STATIC__/js/jquery.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <link rel="stylesheet" href="__STATIC__/layui/css/layui.css">
    <script type="text/javascript" src="__STATIC__/x-admin/js/xadmin.js"></script>
    <link rel="stylesheet" href="__STATIC__/x-admin/css/font.css">
    <link rel="stylesheet" href="__STATIC__/x-admin/css/xadmin.css">
</head>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="#">业务管理</a>
        <a href="#">业务分部</a>
        <a href="#">添加代理人</a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>

<form class="layui-form" onsubmit="return false" id="add" style="width: 500px;padding-top: 20px">

    <div class="layui-form-item">
        <label class="layui-form-label" >代理人姓名</label>
        <div class="layui-input-block">
            <input type="text" id="name" name="name" required  lay-verify="required" placeholder="请输入代理人姓名" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" >代理人手机</label>
        <div class="layui-input-block">
            <input type="text" id="phone" name="phone" required  lay-verify="required" placeholder="请输入代理人联系手机，手机号即为账号" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" >代理人密码</label>
        <div class="layui-input-block">
            <input type="password" id="pwd" name="pwd" required  lay-verify="required" placeholder="请输入代理人密码" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" >密码确认</label>
        <div class="layui-input-block">
            <input type="password" id="is_pwd" name="is_pwd" required  lay-verify="required" placeholder="请再次输入代理人密码" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" >代理人地址</label>
        <div class="layui-input-block">
            <input type="text" id="address" name="address" required  lay-verify="required" placeholder="请输入代理人详细地址" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" >代理人邮箱</label>
        <div class="layui-input-block">
            <input type="text" id="email" name="email" required  lay-verify="required" placeholder="请输入代理人联系邮箱" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">代理类型</label>

        <div class="layui-input-block">
            <select name="type" lay-verify="required" id="type">
                {foreach $type as $val}
                <option value="{$val.id}" >{$val.name}</option>
                {/foreach}
            </select>
        </div>

    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">代理人备注</label>
        <div class="layui-input-block">
            <textarea name="remark" placeholder="请输入内容" class="layui-textarea" id="remark"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" id="sub" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
</div>
</body>
</html>
<script>
    layui.use('layer',function(){
        layer = layui.layer;
    });
</script>
<script>
    $("#sub").click(function(){
        //正则
        var patrn = /^(\w){6,20}$/;
        var phone_rule = /^1(3|4|5|7|8)\d{9}$/;
        var email_rule    = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/;

        var pwd     = $("#pwd").val();
        var is_pwd  = $("#is_pwd").val();
        var phone   = $("#phone").val();
        var email   = $("#email").val();

        if(!phone_rule.test(phone)){
            layer.msg('手机号不符合规范',{icon:5,time:2000});
            return;
        }
        if(!patrn.test(pwd)){
            layer.msg('代理密码太短',{icon:5,time:2000});
            return;
        }
        if(pwd != is_pwd){
            layer.msg('两次密码不一致',{icon:5,time:2000});
            return;
        }
        if(!email_rule.test(email)){
            layer.msg('邮箱不符合规范',{icon:5,time:2000});
            return;
        }
        $.ajax({
            url:"{:url('/customer/userAdd')}",
            data:$("#add").serialize(),
            type:"post",
            dataType:"json",
            success:function(res){
                if(res.code){
                    layer.msg(res.msg,{icon:1,time:2000},function(){
                        window.location.reload();
                    });
                    return;
                }else{
                    layer.msg(res.msg,{icon:5,time:2000});
                    return;
                }
            }
        })
    });
</script>